/* Copyright (c) 2010, Shawn McGregor and Steve Mitchell All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. A6281.c Notes: ShiftBrites require up to 60mA per module when all LEDs are active. The supply voltage should be kept between 5.5 and 9 volts. */ #include #include #include "A6281.h" /*********************************************************************************************** * * shiftbrite_init * * Before using, setup the A628a’s internal clock and write the dot correction values. * Data is handed out highest bit to lowest bit order. * * WRITE: 0x47 <- we write 32bits of data total * WRITE: 0xF1 * WRITE: 0xFC * WRITE: 0x7F * Latch DISABLED <- set latch pin high * Latch ENABLED <- set latch pin low * ************************************************************************************************/ void shiftbrite_init(void) { SB_Latch_DIR=0; //setup latch pin SB_Latch=0; SB_Data_DIR=0; //setup data pin SB_Data=0; SB_Clock_DIR=0; //setup clock pin SB_Clock=0; Delay10KTCYx(20); //delay before chip communication write8bit(0x47); //setup chip write8bit(0xf1); write8bit(0xfc); write8bit(0x7f); SB_Latch=1; Delay10TCYx(255); SB_Latch=0; shiftbrite_color(0x0000, 0x0000, 0x0000); } /*********************************************************************************************** * * shiftbrite_rgbchk * ************************************************************************************************/ void shiftbrite_rgbchk(void) { shiftbrite_color(0x3FF, 0x3ff, 0x3ff); Delay10KTCYx(255); shiftbrite_color(0x3FF, 0, 0); Delay10KTCYx(255); shiftbrite_color(0, 0x3FF, 0); Delay10KTCYx(255); shiftbrite_color(0,0,0x3FF); Delay10KTCYx(255); } /*********************************************************************************************** * * shiftbrite_color (red, green, blue) * ************************************************************************************************/ void shiftbrite_color(unsigned int r, unsigned int g, unsigned int b) { SB_Latch=0; write1bit(0); // color set command begin 00 write1bit(0); write10bit(b); // shift out value blue write10bit(r); // shift out value red write10bit(g); // shift out value green SB_Latch=1; Delay10TCYx(255); SB_Latch=0; } /*********************************************************************************************** * * write10bit (c) * ************************************************************************************************/ void write10bit(unsigned int i) { volatile unsigned char c; for(c=0; c<10; c++){ if(i & 0b1000000000) SB_Data=1; else SB_Data=0; Delay10TCYx(255); SB_Clock=1; Delay10TCYx(255); SB_Clock=0; i=i<<1; } } /*********************************************************************************************** * * write8bit(c) * ************************************************************************************************/ void write8bit(unsigned char c) { volatile unsigned char i; for(i=0; i<8; i++){ if(c & 0b10000000) SB_Data=1; else SB_Data=0; Delay10TCYx(255); SB_Clock=1; Delay10TCYx(255); SB_Clock=0; c=c<<1; } } /*********************************************************************************************** * * write1bit(c) * ************************************************************************************************/ void write1bit(unsigned char c) { SB_Data=c; Delay10TCYx(255); SB_Clock=1; Delay10TCYx(255); SB_Clock=0; }